<template>
	<view class="sort-info">
		<!-- 返回 -->
		<!-- 	<view class="back" @click="back"><</view> -->
		<!-- 信息 -->
		<view class="content">
			<view class="img">
				<image :src="list.goods_image" mode="aspectFill"></image>
			</view>
			<view class="content-right">	
			<view class="title"><text>{{list.title}}</text></view>
			<view class="center">
				<text>安全稳定</text>
				<text>联合高产出</text>
			</view>
			<view class="money">{{list.goods_price}} <text class="danwei">USDT</text></view>
			</view>
		</view>

		<view class="headTitle">
			<view v-for="(x,y) in selectHead" :key="y" :class="{'selected' : y == selected}" @click="select(y)">{{x}}
			</view>
		</view>

		<swiper :current="selected" @change="current" :style="{ height: swiperHeight + 'px' }">
			<swiper-item>
				<view class="swiper-item"  id="content-wrap0">
					<sort-infoParameter :list="list"></sort-infoParameter>
				</view>
			</swiper-item>
			<swiper-item>
				<view class="swiper-item" id="content-wrap1">
					<sort-infoExplain :list="list.goods_content"></sort-infoExplain>
				</view>
			</swiper-item>
			<swiper-item>
				<view class="swiper-item" id="content-wrap2">
					<sort-infoTips></sort-infoTips>
				</view>
			</swiper-item>
		</swiper>
		
		

	</view>
</template>

<script>
	import parameter from '../../components/sort-infoParameter/sort-infoParameter.vue'
	import explain from '../../components/sort-infoExplain/sort-infoExplain.vue'
	import tips from '../../components/sort-infoTips/sort-infoTips.vue'
	import api from '../../common/api.js'
	export default {
		components: {
			parameter,
			explain,
			tips,
		},
		data() {
			return {
				list: '',
				selected: 0,
				type: 'top',
				order_sn: '',
				order: '',
				swiperHeight: ''
			}
		},
		computed: {
			selectHead() {
				return [
					this.$t('shebei.shebeiInfo.parameter'),
					this.$t('shebei.shebeiInfo.explain'),
					this.$t('shebei.shebeiInfo.tips'),
				]
			}
		},
		mounted(args) {
		    //动态设置swiper的高度
		    this.$nextTick(() => {
		      this.setSwiperHeight();
		    });
		  },
		methods: {
			 setSwiperHeight() {
				  let element = "#content-wrap" + this.selected;
				  console.log('element', element)
			      let query = uni.createSelectorQuery().in(this);
			      query.select(element).boundingClientRect();
			      query.exec((res) => {
					  console.log('element', res)
			        if (res && res[0]) {
			          this.swiperHeight = res[0].height;
					  console.log('element', this.swiperHeight)
			        }
			      });
			    },
			back() {
				uni.navigateBack({})
			},
			select(x) {
				this.selected = x
			},
			current(e) {
				this.selected = e.detail.current
				console.log(12313)
				this.$nextTick(() => {
					this.setSwiperHeight();
				  });
			}
		},
		onLoad(res) {
			console.log(res);
			// 获取商品信息
			this.$api.sendRequest({
				url:api.GOODS_INFO,
				data:{
					goodsid:res.id
				},
				success:res=>{
					this.list=res.data
					var that=this;
					console.log(this.list);
					setTimeout(function(){
					that.list.goods_image=api.HOST+that.list.goods_image
					},300)
				}
			})
		},
		created() {

		}
	}
</script>
<style>
	page {
		background-color: #F3F3F3;
	}
</style>
<style scoped lang="scss">
	.sort-info {
		padding-bottom: 200rpx;
	}
	.back {
		font-size: 2em;
		margin-left: 20rpx;
	}

	.content {
		margin: 24rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, .1);
		border-radius: 14rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		display: flex;
		flex-direction: row;
		padding: 24rpx 0 24rpx 0;
		align-items: center;
		.img {
			width: 222rpx;
			height: 140rpx;
			border-radius: 20rpx;
			overflow: hidden;
			display: flex;
			justify-content: center;
			margin-left: 30rpx;
			margin-right: 40rpx;
		}
	}

	image {
		width: 100%;
		height: 100%;
	}
	.content-right{
		margin: 20rpx 0;
		margin-right: 20rpx;
	}
	.title {
		font-size: 1em;
		font-weight: bold;
		color: #005FDB;
	}

	.center {
		width: 300rpx;
		font-size: .7em;
		margin: 20rpx 0;
	}

	.center>text:nth-of-type(1) {
		width: 200rpx;
		padding: 0 10rpx;
		background-color: #FFCFCF;
		margin-right: 10rpx;
		color: #D87575;
	}

	.center>text:nth-of-type(2) {
		width: 200rpx;
		padding: 0 10rpx;
		background-color: #D5CFFF;
		color: #7E75D8;
	}

	.money {
		color: #FF0000;
		font-weight: bold;
		font-size: 1.3em;
		margin-top: 20rpx;
	}

	.danwei {
		padding-left: 10rpx;
		font-size: .8em;
	}

	.headTitle {
		display: flex;
		font-weight: bold;
		margin-top: 20rpx;
		justify-content: space-evenly;
		color: #474747;
	}

	.selected {
		color: #000000;
		border-bottom: 6rpx solid #005FDB;
	}

	swiper {
		width: 94%;
		margin: 20rpx auto;
		height: 50vh;
		background-color: #FFFFFF;
	}

	button {
		position: fixed;
		bottom: 5vh;
		left: calc(50% - 43%);
		width: 86%;
		background-color: #207DFE;
		color: #FFFFFF;
	}
</style>
